/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    bool isSub(TreeNode* A, TreeNode* B)
    {
        if(B==nullptr)
            return true;
        if(A==nullptr)
            return false;
        if(A->val==B->val && isSub(A->left,B->left)&& isSub(A->right,B->right))
        {
            return true;
        }
        return false;
    }
    bool isSubStructure(TreeNode* A, TreeNode* B) {
        if(B==nullptr || A==nullptr)
        {
            return false;
        }
        return isSub(A,B) || isSubStructure(A->left,B) || isSubStructure(A->right,B);
    }
};
